package top.xuziyi.crawler.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xuziyi.common.pojo.StockLb;
import top.xuziyi.crawler.dao.StockLbDao;

import java.util.List;

@Service
public class StockLbService {

    @Autowired
    private StockLbDao stockLbDao;

    /**
     * 批量新增股票列表
     *
     * @param list
     */
    @Transactional
    public void batchSave(List<StockLb> list) {
        for (StockLb stockLb : list) {
            if (stockLbDao.findBySymbol(stockLb.getSymbol()) == 0) {
                stockLbDao.save(stockLb);
            }
        }
    }

    public List<StockLb> findAll() {
        return stockLbDao.findAll();
    }

    /**
     * 根据股票代码修改状态
     *
     * @param symbol
     * @param status
     */
    @Transactional
    public void updateStatus(String symbol, String status) {
        stockLbDao.updateStatus(status, symbol);
    }
}
